package com.lgl.utils;


import com.lgl.entity.Article;
import com.lgl.vo.HotArticleVo;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class BeanCopyUtils {
    public static <V> V beanCopy(Object resource, Class<V> vClass) {
        V result = null;
        try {
            result = vClass.newInstance();
            BeanUtils.copyProperties(resource, result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public static <O, V> List<V> copyBeanList(List<O> list, Class<V> clazz) {
        List articleList = new ArrayList<V>();
        for (O o:list){
            try {
                V v = clazz.newInstance();
                BeanUtils.copyProperties(o,v);
                articleList.add(v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return articleList;
    }

}
